﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AnLe.Models;

namespace AnLe.Controllers
{
    public class AccountController : Controller
    {
        public ActionResult Login()
        {
            return View();
        }

        [HttpPost]
        public ActionResult LogOn(FormCollection form)
        {

            if (!String.IsNullOrEmpty(form["username"]) && !String.IsNullOrEmpty(form["password"]))
            {
                User user = UsersModels.getUserInfo(form["username"], form["password"]);
                if (user != null)
                {
                    Session["username"] = user.UserName;
                    Session["userID"] = user.UserID;
                    Session["usertype"] = user.UserType;
                    return RedirectToAction("Index", "Administrator");
                }
                else
                {
                    return RedirectToAction("LogOn", "Account");
                }

            }
            return View("");

        }

    }
}
